import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray';
import * as Rules from '../../rules';
/**
 * 获取校验规则
 * @param props
 * @returns
 */
export var getRulesFromProps = function getRulesFromProps(props, form) {
  if (typeof props.rules === 'function') return props.rules;
  var rules = [];
  if (
    props.required !== false &&
    (!props.rules ||
      !props.rules.some(function (rule) {
        return rule.required;
      }))
  ) {
    rules.push({
      required: true,
      message: '\u8BF7\u8F93\u5165'.concat(props.label),
      whitespace: true,
    });
  }
  if (props.valueType && Rules[props.valueType]) {
    var valueType = props.valueType;
    rules.push(Rules[valueType]);
  }
  // 防止 xss 攻击
  rules.push(Rules.xss);
  if (form && props.rules) {
    rules = [].concat(_toConsumableArray(rules), _toConsumableArray(props.rules));
  }
  return rules;
};
/**
 * 获取额外的 props 属性
 * @param type
 * @returns
 */
export var getExtraProps = function getExtraProps(props, form) {
  var extraProps = {};
  if (props.valueType) {
    switch (props.valueType) {
      case 'mobileCn':
        extraProps.type = 'phone';
        extraProps.maxLength = 11;
        break;
      case 'idCard':
        extraProps.maxLength = 18;
        break;
    }
  }
  return extraProps;
};
